package edu.towson.greenteam.comment;
import java.util.ArrayList;
import edu.towson.greenteam.Iterator;

import edu.towson.greenteam.Collection;


public class Comments implements Collection<Comment>
{
	
	protected ArrayList<Comment> currentComments;
	private int lastID;
	
	
	public Comments() {
		currentComments = new ArrayList<Comment>();
		lastID = 0;
	}
	
	public boolean add(String content, String custname) {
		int newid = lastID+1;
		Comment newComment = new Comment(newid, content, custname);
		return currentComments.add(newComment);
	}
	
	@Override
	public boolean add(Comment e) {
		boolean r=false;
		int newid = lastID++;
		Comment newComment = new Comment(newid);
		{
			newComment.setContent(e.getContent());
			newComment.setCustName(e.getCustName());
			newComment.setReviewed(e.isReviewed());
			newComment.setVisible(e.isVisible());
		    r = currentComments.add(newComment);
		}
		return r;
	}
	
	@Override
	public boolean update(Comment e) {
		//BUG: use ID to get by index
		Iterator<Comment> commentItr = (Iterator<Comment>)currentComments.iterator();
		while (commentItr.hasNext())
		{
			Comment thisComment = commentItr.next();
			if (thisComment == e)
			{
				currentComments.remove(thisComment);
				currentComments.add(e);
				return true;
			}
		}
		return false;
	}

	@Override
	public boolean contains(Comment e) {
		return currentComments.contains(e);
	}

	@Override
	public boolean remove(Comment e) {
		return currentComments.remove(e);
	}

	@Override
	public boolean isEmpty() {
		return currentComments.isEmpty();
	}

	@Override
	public int size() {
		return currentComments.size();
	}

	public Comment get(int i) {
		//check to make sure i is less than size
		if (currentComments.size() > i)
		{
			return currentComments.get(i);
		}
		else 
		{
			return null;
		}
	}
	
	/****Iterators****/
	/*****************/
	
	public Iterator<Comment> createItr() {
		return (Iterator<Comment>)currentComments.iterator();
	}
	
	public Iterator<Comment> createCCNotReviewedItr() {
		return new CCNotReviewedItr(this);
		
	}
	
	public Iterator<Comment> createCCVisibleItr() {
		return (Iterator<Comment>)new CCVisibleItr(this);
	}

}
